package com.gm.controller;

import com.gm.bean.User;
import com.gm.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Administrator
 * @Date 2020/6/19 16:24
 **/
@RestController
public class UserController {
    @Autowired
    UserRepository userRepository;
    @GetMapping("/user/{id}")
    public User getUserById(@PathVariable("id") Integer id){
        User user = userRepository.getOne(id);
        return user;
    }
    @GetMapping("/user")
   public User addUser(User user){
       User user1 = userRepository.save(user);
       return user1;
   }
}
